package ru.gerunn.silent.io;

import java.io.IOException;
import java.io.ObjectOutputStream;

import javax.net.ssl.SSLSocket;

import ru.gerunn.silent.message.Message;

public class SocketWriter implements Writer {

	private final ObjectOutputStream writer;

	public SocketWriter(final SSLSocket socket) throws WriterException {
		try {
			writer = new ObjectOutputStream(socket.getOutputStream());
		} catch (IOException e) {
			throw new WriterException(e);
		}
	}

	public void write(final Message message) throws WriterException {
		try {
			writer.writeObject(message);
			writer.flush();
		} catch (IOException e) {
			throw new WriterException(e);
		}
	}

}
